package com.cc8w.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * aop传参数测试
 */

@Aspect
@Component
public class ArgsAspect {
    private Logger logger = LoggerFactory.getLogger(WebLogAspect.class);



    /**
     * 定义切入点，切入点为com.cc8w.home.service下的所有函数
     */
    @Pointcut(value="execution(public * com.cc8w.home.service.UserService.queryUserByName(java.lang.String))  && args(userName)", argNames="userName")
    public void webLog(String userName){}

    @Before(value="webLog(userName)")
    public void beforeWithParam(JoinPoint joinPoint, String userName) {
            System.out.println(this.getClass().getName()+" fun: beforeWithParam; userName is : " + userName);
    }

    @After(value="bean(userService) && execution(* queryUserByName(java.lang.String)) && args(userName)", argNames="userName")
    public void afterWithParam(String userName){
        System.out.println(this.getClass().getName()+" fun: afterWithParam; userName is : " + userName);
    }





}
